<template>
	<view class="p-10">


		<view class="bg-white p-20 " style="padding-bottom: 50px">
			<view  class="p-b-10  a-c" style="flex-wrap: wrap;display: flex;">
				<view class="" style="margin: 10rpx;width: 150px;">
					<uni-data-select @change="change_category_id" :value="find.category_id"
						:localdata="localdata_category_id">
					</uni-data-select>
				</view>
				<view class="" style="margin: 10rpx;">
					<uni-easyinput confirm-type="search" @confirm="on_search" v-model="find.city" placeholder="请输入城市">
					</uni-easyinput>
				</view>
				<view class="" style="margin: 10rpx;">
					<uni-easyinput confirm-type="search" @confirm="on_search" v-model="find.title" placeholder="请输入标题">
					</uni-easyinput>
				</view>
				<view class="banmi_flex">
					<view style="padding: 0 7rpx;"> <button @click="on_search()" type="primary" size="mini"> 查询
						</button>
					</view>
					<view style="padding: 0 7rpx;"> <button @click="on_search_resetting()" type="primary" size="mini">
							重置 </button>
					</view>
					<view style="padding: 0 7rpx;"> <button @click="on_add()" type="primary" size="mini"> 新增 </button>
					</view>

				</view>
			</view>
			<uni-table  border stripe type="selection"
				@selection-change="selectionData">
				<uni-tr style=" position:sticky;top: 0;z-index: 199;">

					<uni-th align="center" >id</uni-th>

					<uni-th align="center" >分类</uni-th>

					<uni-th align="center" >城市</uni-th>

					<uni-th align="center" >标题</uni-th>

					<uni-th align="center" >封面</uni-th>

			 
					
					<uni-th align="center" >阅读量</uni-th>

					<uni-th align="center" >点赞量</uni-th>

					<uni-th align="center" >分享量</uni-th>

					<uni-th align="center" >创建时间</uni-th>

					<uni-th align="center" >最后更新</uni-th>

					<uni-th align="center" >是否显示</uni-th>

					<uni-th align="center" >创建者ip</uni-th>
					<uni-th align="center" >状态</uni-th>


					<uni-th align="center"  class="operate_right">操作</uni-th>

				</uni-tr>
				<uni-tr v-for="(vo,index) in list" :key="index">
					<uni-td align="center" >
						{{vo.id}}
					</uni-td>
					<uni-td align="center" >
						{{vo.name}}
					</uni-td>
					<uni-td align="center" >
						{{vo.city}}
					</uni-td>
					<uni-td align="center" >
						{{vo.title}}
					</uni-td>
					<uni-td align="center" >
						<image v-if="vo.img" class="b_y" @click="on_img(vo.img)" :src="vo.img|getImg" style="height: 120rpx;"
							mode="heightFix">
						</image>
					</uni-td>
		 
			
					<uni-td align="center" >
						{{vo.read}}
					</uni-td>
					<uni-td align="center" >
						{{vo.like}}
					</uni-td>
					<uni-td align="center" >
						{{vo.share}}
					</uni-td>
					<uni-td align="center" >
						{{vo.create_time}}
					</uni-td>
					<uni-td align="center" >
						{{vo.update_time}}
					</uni-td>
					<uni-td >
						<view @click="on_switch_open(index,vo.open)">
							<banmi-switch :is_state="vo.open" is_type='2'></banmi-switch>
						</view>
					</uni-td>

					<uni-td align="center" >
						{{vo.userip}}
					</uni-td>
					<uni-td align="center" >
						{{vo.status}} - <text class="cred" v-if="vo.status=='被拒绝'">{{vo.refuse}}</text>
					</uni-td>
					<uni-td class="operate_right" buts="buts">
					<!-- 	<view class="t-c">
							<button @click="on_top(index)" class="operate_button" type="primary" size="mini">置顶</button>
						</view>
						<view class="t-c">
							<button @click="on_refresh(index)" class="operate_button" type="primary"
								size="mini">刷新</button>
						</view> -->

						<view class="t-c" v-if="vo.status=='审核中'||vo.status==='被拒绝'">
							<button @click="on_pass(index)" class="operate_button" type="primary"
								size="mini">通过</button>
						</view>
						<view class="t-c" v-if="vo.status=='审核中'">
							<button @click="on_refuse(index)" type="primary" class="operate_button"
								style="background-color: red;" size="mini">拒绝</button>
						</view>

						<view class="t-c">
							<button @click="on_edit(index)" class="operate_button" type="primary" size="mini">
								编辑
							</button>
						</view>
						<view class="t-c">
							<button @click="on_dels(index)" class="operate_button " type=""
								size="mini">删除</button>
						</view>
					</uni-td>
				</uni-tr>
			</uni-table>
			<view class=" p-t-20 bg-white">
				<uni-pagination @change="getPage" show-icon="true" :total="total" current="1"
					style="float: left;margin-bottom: 10px;"></uni-pagination>
			</view>

			<uni-popup ref="component_pass" type="center">
				<pass :id="id" @confirm="confirm_pass">
				</pass>
			</uni-popup>
			<uni-popup ref="component_refuse" type="center">
				<refuse :id="id" @confirm="confirm_refuse">
				</refuse>
			</uni-popup>
			<edit ref="component_edit" @confirm="confirm_edit">
			</edit>
			<uni-popup ref="component_dels" type="center">
				<dels :id="id" @confirm="confirm_dels">
				</dels>
			</uni-popup>
			<tops ref="component_top" @confirm="confirm_top">
			</tops>
		</view>
	</view>
</template>

<script>
	import pass from './pass.vue';
	import refuse from './refuse.vue';
	import edit from './edit.vue';
	import dels from './dels.vue';
	import tops from './tops.vue';
	export default {
		components: {
			pass,
			refuse,
			edit,
			dels,
			tops
		},
		data() {
			return {

				localdata_category_id: [],
				find: {},
				list: [],
				total: 0,
				page: 1,
				id: 0,
				is_top_height: false,
			}
		},
		onLoad(on) {
			this.init_category_id();
			this.init();
		},
 
		methods: {
			on_top(index) {
				this.id = this.list[index]['id'];
				this.$refs.component_top.init(this.id)
			},
			confirm_top() {

			},
			//全选 反选
			selectionData(list) {
				console.log("list: " + JSON.stringify(list));
			},
			on_refresh(index) {
				var that = this;
				uni.showModal({
					title: '提示',
					content: '确认刷新吗？',
					success: function(res) {
						if (res.confirm) {
							that.ajax_refresh(index);
						}
					}
				});
			},
			ajax_refresh(index) {
				var that = this;
				var id = this.list[index]['id'];
				let requestParams = {
					id: id,
				};
				this.Http.post('/banmichaoqiangbizhi/admin/Article/refresh', requestParams).then(ret => {
					uni.showToast({
						title: ret.msg,
						icon: 'none'
					})
				})
			},

			on_img(img) {
				if (img.indexOf("http") != -1) {
					return img;
				}
				img = uni.getStorageSync('img_url') + img
				uni.previewImage({
					current: img,
					urls: [img]
				})
			},
			on_switch_open(index, val) {
				var that = this;
				var id = this.list[index]['id'];
				let requestParams = {
					id: id,
				};
				this.Http.post('/banmichaoqiangbizhi/admin/Article/switch_open', requestParams).then(ret => {
					this.list[index]['open'] = ret.data
				})
			},

			on_pass(index) {
				this.id = this.list[index]['id'];
				this.$refs.component_pass.open()
			},
			confirm_pass() {
				this.init();
				this.$refs.component_pass.close()
			},

			on_refuse(index) {
				this.id = this.list[index]['id'];
				this.$refs.component_refuse.open()
			},
			confirm_refuse() {
				this.init();
				this.$refs.component_refuse.close()
			},
			on_edit(index) {
				this.id = this.list[index]['id'];
				this.$refs.component_edit.init(this.id)
			},
			confirm_edit() {
				if (this.id == 0) {
					this.page = 1;
				}
				this.init();

			},
			on_dels(index) {
				this.id = this.list[index]['id'];
				this.$refs.component_dels.open()
			},
			confirm_dels() {
				this.init();
				this.$refs.component_dels.close()
			},

			change_category_id(e) {
				this.find.category_id = e;
			},
			init_category_id() {
				var that = this;
				let requestParams = {};
				this.Http.post('banmichaoqiangbizhi/admin/Article/class_category_id', requestParams).then(ret => {
					if (ret.status == 200) {
						var old_list = ret.data.list;
						var list = [];
						for (var i = 0; i < old_list.length; i++) {
							var find = {
								text: old_list[i]['name'],
								value: old_list[i]['id'],
							}
							list.push(find);
						}
						this.localdata_category_id = list;
					}
				})
			},

			getPage(id) {
				this.page = id.current;
				this.init()
			},
			on_add() {
				this.id = 0;
				this.$refs.component_edit.init(0)
			},
			on_search() {
				this.init();
			},
			on_search_resetting() {
				this.find = {};
				this.page = 1;
				this.init();
			},
			init() {
				var that = this;
				this.find['page'] = this.page
				this.Http.post('banmichaoqiangbizhi/admin/Article/lists', this.find).then(ret => {
		 
					var list = ret.data.list.list.data;
					 
					this.list = list;
					this.total = ret.data.list.list.total;
				})
			},
		}
	}
</script>

<style>
	.operate_button {
		width: 70px;
	}

	.operate_right {
		position: sticky;
		right: 0;
		z-index: 100;
		background-color: #fff;
	}
</style>